package com.ruoyi.assignmentsubmission.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.classperformance.domain.Classperformance;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.assignmentsubmission.domain.Assignmentsubmission;
import com.ruoyi.assignmentsubmission.service.IAssignmentsubmissionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生作业提交Controller
 *
 * @author dongyv
 * @date 2025-05-15
 */
@RestController
@RequestMapping("/assignmentsubmission/assignmentsubmission")
public class AssignmentsubmissionController extends BaseController
{
    @Autowired
    private IAssignmentsubmissionService assignmentsubmissionService;

    /**
     * 查询学生作业提交列表
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:list')")
    @GetMapping("/list")
    public TableDataInfo list(Assignmentsubmission assignmentsubmission)
    {
        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            startPage();
            List<Assignmentsubmission> list = assignmentsubmissionService.selectAssignmentsubmissionList(assignmentsubmission);
            return getDataTable(list);
        }
        else
        {
            //学生
            startPage();
            List<Assignmentsubmission> list = assignmentsubmissionService.selectAssignmentsubmissionList_student(teacherId);
            return getDataTable(list);
        }

    }

    /**
     * 导出学生作业提交列表
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:export')")
    @Log(title = "学生作业提交", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Assignmentsubmission assignmentsubmission)
    {
        String teacherId=getUsername();
        if("admin".equals(teacherId))
        {
            //管理员
            List<Assignmentsubmission> list = assignmentsubmissionService.selectAssignmentsubmissionList(assignmentsubmission);
            ExcelUtil<Assignmentsubmission> util = new ExcelUtil<Assignmentsubmission>(Assignmentsubmission.class);
            util.exportExcel(response, list, "学生作业提交数据");
        }
        else
        {
            //学生
            List<Assignmentsubmission> list = assignmentsubmissionService.selectAssignmentsubmissionList_student(teacherId);
            ExcelUtil<Assignmentsubmission> util = new ExcelUtil<Assignmentsubmission>(Assignmentsubmission.class);
            util.exportExcel(response, list, "学生作业提交数据");
        }


    }

    /**
     * 获取学生作业提交详细信息
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:query')")
    @GetMapping(value = "/{submissionId}")
    public AjaxResult getInfo(@PathVariable("submissionId") Long submissionId)
    {
        return success(assignmentsubmissionService.selectAssignmentsubmissionBySubmissionId(submissionId));
    }

    /**
     * 新增学生作业提交
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:add')")
    @Log(title = "学生作业提交", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Assignmentsubmission assignmentsubmission)
    {
        return toAjax(assignmentsubmissionService.insertAssignmentsubmission(assignmentsubmission));
    }

    /**
     * 修改学生作业提交
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:edit')")
    @Log(title = "学生作业提交", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Assignmentsubmission assignmentsubmission)
    {
        return toAjax(assignmentsubmissionService.updateAssignmentsubmission(assignmentsubmission));
    }

    /**
     * 删除学生作业提交
     */
    @PreAuthorize("@ss.hasPermi('assignmentsubmission:assignmentsubmission:remove')")
    @Log(title = "学生作业提交", businessType = BusinessType.DELETE)
	@DeleteMapping("/{submissionIds}")
    public AjaxResult remove(@PathVariable Long[] submissionIds)
    {
        return toAjax(assignmentsubmissionService.deleteAssignmentsubmissionBySubmissionIds(submissionIds));
    }
}
